package com.hsjk.szwj.module.train.service.impl;

import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoCreateReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoDetailRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoPageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoPageRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoPageSearchReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoPageSearchRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCourseVideoUpdateReqVO;
import com.hsjk.szwj.module.train.convert.CourseVideoConvert;
import com.hsjk.szwj.module.train.dal.dataobject.course.CourseVideoDO;
import com.hsjk.szwj.module.train.dal.mysql.course.ICourseVideoMapper;
import com.hsjk.szwj.module.train.service.ICourseVideoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/10/28 18:26
 **/
@Service
public class CourseVideoServiceImpl implements ICourseVideoService {
    @Resource
    private ICourseVideoMapper courseVideoMapper;

    @Override
    public PageResult<AdminCourseVideoPageRespVO> getCourseVideoPage(AdminCourseVideoPageReqVO reqVO) {
        PageResult<CourseVideoDO> courseVideoDOPageResult = courseVideoMapper.selectPage(reqVO);
        return CourseVideoConvert.INSTANCE.convertAdminCourseVideoPageRespVO(courseVideoDOPageResult);
    }

    @Override
    public PageResult<AdminCourseVideoPageSearchRespVO> getCourseVideoSearchPage(AdminCourseVideoPageSearchReqVO reqVO) {
        PageResult<CourseVideoDO> courseVideoDOPageResult = courseVideoMapper.selectPage(reqVO);
        return CourseVideoConvert.INSTANCE.convertAdminCourseVideoPageSearchRespVO(courseVideoDOPageResult);
    }

    @Override
    public AdminCourseVideoDetailRespVO getCourseVideoDetail(Long id) {
        CourseVideoDO courseVideoDO = courseVideoMapper.selectById(id);
        return CourseVideoConvert.INSTANCE.convertAdminCourseVideoDetailRespVO(courseVideoDO);
    }

    @Override
    public Boolean createCourseVideo(AdminCourseVideoCreateReqVO reqVO) {
        CourseVideoDO courseVideoDO = CourseVideoConvert.INSTANCE.convertCourseVideoDO(reqVO);
        int insert = courseVideoMapper.insert(courseVideoDO);
        return insert > 0 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public Boolean updateCourseVideo(AdminCourseVideoUpdateReqVO reqVO) {
        CourseVideoDO courseVideoDO = CourseVideoConvert.INSTANCE.convertCourseVideoDO(reqVO);
        int update = courseVideoMapper.updateById(courseVideoDO);
        return update > 0 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public Boolean deleteCourseVideo(Long id) {
        int result = courseVideoMapper.deleteById(id);
        return result > 0 ? Boolean.TRUE : Boolean.FALSE;
    }
}
